package com.jiuyun.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//没登录不让访问

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name=request.getParameter("stname");
        String pass=request.getParameter("stpass");

        //模拟登录
        if("admin".equals(name) && "123".equals(pass)){
            //成功 session放个标志
            HttpSession session=request.getSession();
            session.setAttribute("login","ok");
            response.sendRedirect("/game.do");
        }else {
            System.out.println("登录失败");
        }
    }
}
